//
// Created by Administrator on 2024/5/21.
//

#include "utils.h"

#ifdef _WINDOWS

#include <windows.h>

double clockX() {
    LARGE_INTEGER frequency;
    QueryPerformanceFrequency(&frequency);
    LARGE_INTEGER count;
    if (!QueryPerformanceCounter(&count)) return -1;
    return double(count.QuadPart) / frequency.QuadPart;
}

void sleep(double s) {
    auto m = DWORD(s * 1000);
    if (m == 0) return;
    Sleep(DWORD(s * 1000));
}

#else

#include <time.h>
#include <unistd.h>

double clockX() {
    struct timespec  ts;
    if(clock_gettime(CLOCK_MONOTONIC, &ts) == -1) return -1
    return (double)ts.tv_sec + (double)ts.tv_nsec/1000000000.0;
}
void sleep(double s) {
    sleep(s);
}
#endif